package main.矩阵;

/**
 * @author tmh
 * @date 2024/7/26 20:38
 * @description
 */
public class T48旋转图像 {
    public void rotate(int[][] matrix) {
        if (matrix.length == 0 || matrix.length != matrix[0].length) {
            return;
        }
        int nums = matrix.length;
        int times = 0;
        while (times <= (nums >> 1)) {
            //len是框框的边长
            int len = nums - (times << 1);
            for (int i = 0; i < len - 1; i++) {
                //暂存左上角的元素
                int temp = matrix[times][times+i];
                //左下角的元素移动到左上
                matrix[times][times+i]=matrix[times+len-1-i][times];
                //右下角的位置移动到左下角
                matrix[times+len-i-1][times]=matrix[times+len-1][times+len-i-1];
                //右上角的位置移动到右下角
                matrix[times+len-1][times+len-i-1]=matrix[times+i][times+len-1];
                //右上角的位置移动到左上角
                matrix[times+i][times+len-1]=temp;
            }
            times++;
        }
    }
}
